package com.ljc;

import java.util.Arrays;

/**
 * @author ljchen on 2022/1/21
 * //Given an array of integers nums and an integer target, return indices of the
 * //two numbers such that they add up to target.
 * // You may assume that each input would have exactly one solution, and you may
 * //not use the same element twice.
 */
public class E1TwoSum {
    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,5,7};
        int target = 7;
        int[] result = twoSum(nums, target);
        System.out.println(Arrays.toString(result));
    }

    public static int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    return new int[] { i, j };
                }
            }
        }
        return new int[] {};
    }
}
